using Godot;
using System;
using Legendofthebrave.Scripts.Characters;

public partial class Enemy : CharacterBody2D
{
    protected Node2D Graphics;
    protected AnimationPlayer AnimationPlayerNode;
    protected StateMachine StateMachineNode;
    protected float gravity;
    
    protected enum Direction
    {
        LEFT = -1,
        RIGHT = 1,
    }
    
    protected Direction direction;
    
    [Export] protected float MaxSpeed = 180.0f;
    [Export] protected float Acceleration = 2000.0f;

    public override void _Ready()
    {
        direction = Direction.LEFT;
        Graphics = GetNode<Node2D>("Graphics");
        AnimationPlayerNode = GetNode<AnimationPlayer>("AnimationPlayer");
        StateMachineNode = GetNode<StateMachine>("StateMachine");
        gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
     
    }

    
    public void Move(float speed,double delta)
    {
        Velocity = new(Mathf.MoveToward(Velocity.X, (int)direction * speed, Acceleration * (float)delta),Velocity.Y + gravity * (float)delta);
        Graphics.Scale = new Vector2(-(int)direction, Graphics.Scale.Y);
        MoveAndSlide();
    }
}
